package net.yunxinyong.cec.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import net.yunxinyong.cec.entity.Cec711OneEntity;
import net.yunxinyong.cec.entity.Cec711OneEntityExample;
import net.yunxinyong.cec.entity.Cec711OneEntityExample.Criteria;
import net.yunxinyong.cec.mapper.Cec711OneMapper;
import net.yunxinyong.cec.service.Cec711OneService;
import net.yunxinyong.cec.utils.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class Cec711OneServiceImpl implements Cec711OneService {
    @Autowired
    private Cec711OneMapper cec711OEIM;

    @Override
    public PageBean<Cec711OneEntity> findAll(int page,int rows,Cec711OneEntity cecOne) {
        Cec711OneEntityExample cec711OneEntityExample = new Cec711OneEntityExample();
        Criteria criteria = cec711OneEntityExample.createCriteria();
        if(cecOne.getId()!=null){
            criteria.andIdEqualTo(cecOne.getId());
        }
        if (page != 0 && rows != 0) {
            PageHelper.startPage(page, rows);
        }
        List<Cec711OneEntity> list = cec711OEIM.selectByExample(cec711OneEntityExample);
        //设置分页信息
        PageBean<Cec711OneEntity> pageBean = new PageBean<>();
        PageInfo<Cec711OneEntity> pageInfo = new PageInfo<>(list);
        pageBean.setTotal(pageInfo.getTotal());
        pageBean.setTotalPages(pageInfo.getPages());
        pageBean.setPageDatas(list);
        return pageBean;
    }

    @Override
    public List<Cec711OneEntity> findOneByBaseId(int baseid) {
        Cec711OneEntityExample cOEIE = new Cec711OneEntityExample();
        Criteria criteria = cOEIE.createCriteria();
        criteria.andBaseIdEqualTo(baseid);
        List<Cec711OneEntity> list = cec711OEIM.selectByExample(cOEIE);
        return list;
    }

    @Override
    public int updateById(int id, int status) {
        Cec711OneEntity cec711OneEconomicIndicator = new Cec711OneEntity();
        cec711OneEconomicIndicator.setId(id);
        cec711OneEconomicIndicator.setStatus(status);
        cec711OneEconomicIndicator.setUpdateTime(new Date());
        int count = cec711OEIM.updateByPrimaryKeySelective(cec711OneEconomicIndicator);
        return count;
    }

    @Override
    public int deleteById(int id) {
        Cec711OneEntity cec711OneEconomicIndicator = new Cec711OneEntity();
        cec711OneEconomicIndicator.setId(id);
        cec711OneEconomicIndicator.setStatus(1);
        int count = cec711OEIM.updateByPrimaryKeySelective(cec711OneEconomicIndicator);
        return count;
    }

    //添加企业信息
    @Override
    public int insertOne(int baseid) {
        Cec711OneEntity cec711OneEconomicIndicator = new Cec711OneEntity();
        cec711OneEconomicIndicator.setBaseId(baseid);
        //更改表时间
        cec711OneEconomicIndicator.setUpdateTime(new Date());
        //创建表时间
        cec711OneEconomicIndicator.setCreateTime(new Date());
        int count = cec711OEIM.insertSelective(cec711OneEconomicIndicator);
        return count;
    }
}
